import { defineStore } from 'pinia'
import { informTypes } from '@globalTypes/global'
import { ref } from 'vue'

export const useInformStore = defineStore(
  'inform',
  () => {
    const informList = ref<informTypes.InformItem[]>([])
    // 添加空闹钟
    const addEmptyInform = () => {
      let inform: informTypes.InformItem = {
        id: new Date().getTime().toString(),
        time: '00:00',
        content: '',
        bgcolor: '#ff0000',
        color: '#fff'
      }
      informList.value.push(inform)
    }
    // 根据id删除闹钟
    const deleteInform = (id: string) => {
      informList.value = informList.value.filter((item) => item.id !== id)
    }
    // 根据时间字符串获取闹钟
    const getInformByTimeStr = (timeStr: string): informTypes.InformItem | null => {
      const list = informList.value.filter((item) => item.time === timeStr)
      return list.length === 0 ? null : list[0]
    }
    return {
      informList,
      addEmptyInform,
      deleteInform,
      getInformByTimeStr
    }
  },
  {
    persist: true
  }
)
